﻿using System.ComponentModel;
using PanoramaTestApp.Model;

namespace PanoramaTestApp.ViewModels
{
    public class SettingsViewModel : INotifyPropertyChanged
    {
        public bool UseLocalServer
        {
            get { return GlobalSettings.Default.ServerAddress == GlobalSettings.Default.LocalAddress; }
            set
            {

                if (value)
                {
                    GlobalSettings.Default.ServerAddress = GlobalSettings.Default.LocalAddress;
                    GlobalSettings.Default.ServerHttpAddress = GlobalSettings.Default.LocalHttpAddress; 
                }

                //OnPropertyChanged("UseLocalServer");
                
            }
        }

        public bool UseInternetServer
        {
            get { return GlobalSettings.Default.ServerAddress == GlobalSettings.Default.InternetAddress; }
            set
            {

                if (value)
                {
                    GlobalSettings.Default.ServerAddress = GlobalSettings.Default.InternetAddress;
                    GlobalSettings.Default.ServerHttpAddress = GlobalSettings.Default.InternetHttpAddress; 
                }
                
                //OnPropertyChanged("UseInternetServer");
            }
        }

        public bool UseNameFilter
        {
            get { return GlobalSettings.Default.UseNameFilter; }
            set
            {

                GlobalSettings.Default.UseNameFilter = value;
            }
        }

        public bool UseDateFilter
        {
            get { return GlobalSettings.Default.UseDateFilter; }
            set
            {

                GlobalSettings.Default.UseDateFilter = value;
            }
        }


        public event PropertyChangedEventHandler PropertyChanged;

        protected virtual void OnPropertyChanged(string propertyName)
        {
            PropertyChangedEventHandler handler = PropertyChanged;
            if (handler != null) handler(this, new PropertyChangedEventArgs(propertyName));
        }
    }
}
